﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using ZXing;
using ZXing.QrCode;

namespace Barcode
{
	public class ZXingLearn
	{
		public BitmapImage GetImage()
		{
			var writer = new BarcodeWriter
			{
				Format = BarcodeFormat.QR_CODE,
				Options = new ZXing.Common.EncodingOptions
				{
					Height = 300,
					Width = 500,
					Margin = 10
				},
				
			};
			writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET,"");
			var image = writer.Write("123");
			//var image = new QRCodeLearn().GetQR();

			return BitmapToBitmapImage(image);
		}

		public BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
		{
			MemoryStream ms = new MemoryStream();
			bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
			BitmapImage bit3 = new BitmapImage();
			bit3.BeginInit();
			bit3.StreamSource = ms;
			bit3.EndInit();
			return bit3;
		}
	}
}